package com.sdhs.file.utils;

import com.google.common.collect.Multimap;
import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.errors.*;
import io.minio.messages.ListPartsResult;
import io.minio.messages.Part;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * minio扩展
 * @author admin
 */
public class MzMinioClient extends MinioClient {

    public MzMinioClient(String endpoint, String accessKey, String secretKey) throws IllegalArgumentException {
        super(endpoint, accessKey, secretKey);
    }


    /**
     * 创建分片上传请求
     *
     * @param bucketName       存储桶
     * @param region           区域
     * @param objectName       对象名
     * @param headers          消息头
     * @param extraQueryParams 额外查询参数
     */
    @Override
    public String createMultipartUpload(String bucketName, String region, String objectName, Multimap<String, String> headers, Multimap<String, String> extraQueryParams)
        throws NoSuchAlgorithmException,
            InsufficientDataException,
        IOException,
        InvalidKeyException,
            ServerException,
            XmlParserException,
            ErrorResponseException,
            InternalException,
            InvalidResponseException,
        InvalidBucketNameException {
        return super.createMultipartUpload(bucketName, region, objectName, headers, extraQueryParams);
    }

    /**
     * 完成分片上传，执行合并文件
     *
     * @param bucketName       存储桶
     * @param region           区域
     * @param objectName       对象名
     * @param uploadId         上传ID
     * @param parts            分片
     * @param extraHeaders     额外消息头
     * @param extraQueryParams 额外查询参数
     */
    @Override
    public ObjectWriteResponse completeMultipartUpload(String bucketName, String region, String objectName, String uploadId, Part[] parts, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams) throws NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, ServerException, XmlParserException, ErrorResponseException, InternalException, InvalidResponseException, InvalidBucketNameException {
        return super.completeMultipartUpload(bucketName, region, objectName, uploadId, parts, extraHeaders, extraQueryParams);
    }


    /**
     * 查询分片数据
     *
     * @param bucketName 存储桶
     * @param objectName 对象名
     * @param uploadId   上传ID
     */
    @Override
    public ListPartsResult listParts(String bucketName, String objectName, Integer maxParts, Integer partNumberMarker, String uploadId)
        throws NoSuchAlgorithmException,
            InsufficientDataException,
        IOException,
        InvalidKeyException,
            ServerException,
            XmlParserException,
            ErrorResponseException,
            InternalException,
            InvalidResponseException, InvalidBucketNameException {
        return super.listParts(bucketName, objectName, maxParts, partNumberMarker, uploadId);
    }


}
